Repository navigation
Conversation
The salt-fix auto-write created a sibling temp file in the wp-config.php directory and move()'d it over the original. That requires the *directory* to be writable, but the precheck only verified the *file* was writable — so on the common hardening where wp-config.php is writable yet its directory is locked, the temp creation failed with "Could not write the new configuration. No changes were made." Keep the atomic temp-swap as the preferred path, but fall back to an in-place put_contents() overwrite of wp-config.php when the temp can't be created. Overwriting an existing writable file needs no directory write access, and the content was already validated by the safety gate. Original file mode is preserved on both paths. Bumps version to 1.0.1.
📝 WalkthroughWalkthroughThis PR improves wp-config.php write reliability in the salt-fix function by computing and preserving original file permissions, implementing an atomic temp-file swap with fallback in-place overwrite, and bumps the plugin version to 1.0.1 to release these changes. Changeswp-config write reliability and version 1.0.1 release
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@includes/Installer.php`:
- Around line 493-495: The chmod parsing uses $filesystem->getchmod($path) and
treats only the empty string as failure, so a returned '0' becomes octdec('0') →
0 and passes a 0000 mode to writes; update the logic around $mode_str and $chmod
to treat '0' (and any non-octal or invalid value) as a failure and fall back to
FS_CHMOD_FILE. Specifically, in the Installer.php code that reads $mode_str and
computes $chmod, validate $mode_str using a check like: ensure it's a non-empty
octal string (e.g., matches /^[0-7]+$/) before calling octdec and casting;
otherwise set $chmod = FS_CHMOD_FILE so put_contents() never receives 0000. Make
the change where $mode_str and $chmod are defined (referencing getchmod,
$mode_str, $chmod, and FS_CHMOD_FILE).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 014d313a-8215-4f1d-b3d8-7bab39bc426f
📒 Files selected for processing (3)
includes/Installer.phpmagicauth.phpreadme.txt
| $mode_str = $filesystem->getchmod( $path ); | ||
| $chmod = '' !== $mode_str ? (int) octdec( $mode_str ) : FS_CHMOD_FILE; | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In current WordPress core, what is the documented/actual return type of WP_Filesystem_Base::getchmod(), and can it return false or non-octal strings?
💡 Result:
In current WordPress core, WP_Filesystem_Base::getchmod is documented to return a string (octal-mode string). The Developer/Trac docs for WP_Filesystem_Base::getchmod state the return type as “string”, i.e., “Mode of the file (the last 3 digits)”[1]. In the upstream code for the base class, getchmod($file) simply returns the string '777' unconditionally[2]. Whether it can return false or non-octal strings: - The method is not documented to return false; the docblock specifies @return string[1]. The base implementation does not return false; it returns '777'[2]. - However, concrete filesystem implementations can differ in behavior. In the direct filesystem implementation (class-wp-filesystem-direct.php), getchmod($file) calls fileperms and returns the string '0' on failure; otherwise it returns substr(decoct(@fileperms($file)),-3), which is an octal-derived string[3]. That means the failure case is still a string and still octal-like ("0"), not false. So, in current core as implemented across at least the base class and the direct filesystem implementation, getchmod returns a string and does not return false; on failure it returns the string '0'. It should not return arbitrary non-octal strings under these implementations (it derives the last 3 digits from decoct(fileperms) or returns a fixed octal string), though the base-class stub itself returns '777' regardless of input[2][3].
Citations:
- 1: https://developer.wordpress.org/reference/classes/wp_filesystem_base/getchmod/
- 2: https://github.com/WordPress/wordpress-develop/blob/6.5/src/wp-admin/includes/class-wp-filesystem-base.php
- 3: https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/class-wp-filesystem-direct.php
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and print the relevant section around includes/Installer.php lines ~470-540
FILE="includes/Installer.php"
if [ -f "$FILE" ]; then
echo "== $FILE =="
sed -n '450,540p' "$FILE" | nl -ba | sed -n '1,200p'
else
echo "File not found: $FILE" >&2
exit 1
fi
# Show definitions/usage of put_contents call(s) in this region for $chmod
rg -n "put_contents\\(|\\$chmod" "$FILE" | head -n 50Repository: EtticDevelopment/magicauth
Length of output: 160
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="includes/Installer.php"
echo "== $FILE =="
if [ ! -f "$FILE" ]; then
echo "Missing $FILE" >&2
exit 1
fi
# print with line numbers around the chmod section
sed -n '470,530p' "$FILE" | nl -ba
echo "== Context: chmod usage =="
rg -n "\\$chmod" "$FILE" | head -n 50
echo "== Context: getchmod usage =="
rg -n "getchmod\\(" "$FILE" | head -n 50Repository: EtticDevelopment/magicauth
Length of output: 161
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="includes/Installer.php"
if [ ! -f "$FILE" ]; then
echo "Missing $FILE" >&2
exit 1
fi
sed -n '460,540p' "$FILE" | nl -ba
echo "---- getchmod occurrence ----"
rg -n "getchmod\\(" "$FILE"
echo "---- chmod usage occurrence ----"
rg -n "\\$chmod" "$FILE"Repository: EtticDevelopment/magicauth
Length of output: 114
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="includes/Installer.php"
echo "== Checking file =="
if [ ! -f "$FILE" ]; then
echo "Missing $FILE" >&2
exit 1
fi
echo "Size(bytes): $(stat -c %s "$FILE" 2>/dev/null || echo unknown)"
echo "== Snippet around chmod (lines 475-525) =="
# Use cat -n for line numbers (nl not available)
sed -n '475,525p' "$FILE" | cat -n
echo "== Lines containing getchmod() =="
rg -n "getchmod\\(" "$FILE" || true
echo "== Lines containing $chmod =="
rg -n "\\$chmod" "$FILE" || true
echo "== Lines containing put_contents() =="
rg -n "put_contents\\(" "$FILE" || trueRepository: EtticDevelopment/magicauth
Length of output: 3022
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="includes/Installer.php"
echo "== Snippet around chmod (lines 485-510) =="
sed -n '485,510p' "$FILE" | cat -n
echo "== Full chmod block context (475-515) =="
sed -n '475,515p' "$FILE" | cat -n
echo "== getchmod() occurrences =="
rg -n "getchmod\\(" "$FILE" || true
echo "== octdec() occurrences =="
rg -n "octdec\\(" "$FILE" || true
echo "== put_contents() occurrences near chmod block =="
rg -n "put_contents\\(.*\\$chmod|put_contents\\(.*?,\\s*\\$updated,\\s*\\$chmod|put_contents\\(\\s*\\$path,\\s*\\$updated,\\s*\\$chmod|put_contents\\(\\s*\\$path,\\s*\\$updated" "$FILE" || true
# Safe check for raw "$chmod" text (no bash $ expansion)
echo "== Lines containing literal '$chmod' =="
grep -nF '$chmod' "$FILE" || trueRepository: EtticDevelopment/magicauth
Length of output: 4161
Harden chmod parsing to avoid applying 0000 when getchmod() fails
WP_Filesystem_*::getchmod() is expected to return an octal-mode string, and WP_Filesystem_Direct::getchmod() returns the string '0' when it can’t read permissions. Current logic only falls back on '', so '0' !== $mode_str and octdec('0') produces $chmod = 0, which is then passed to put_contents() for both the atomic temp swap and the in-place fallback writes.
$mode_str = $filesystem->getchmod( $path );
$chmod = '' !== $mode_str ? (int) octdec( $mode_str ) : FS_CHMOD_FILE;Proposed fix
- $mode_str = $filesystem->getchmod( $path );
- $chmod = '' !== $mode_str ? (int) octdec( $mode_str ) : FS_CHMOD_FILE;
+ $mode_raw = $filesystem->getchmod( $path );
+ $mode_str = is_string( $mode_raw ) ? trim( $mode_raw ) : '';
+ $chmod = preg_match( '/^[0-7]{3,4}$/', $mode_str ) ? (int) octdec( $mode_str ) : FS_CHMOD_FILE;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@includes/Installer.php` around lines 493 - 495, The chmod parsing uses
$filesystem->getchmod($path) and treats only the empty string as failure, so a
returned '0' becomes octdec('0') → 0 and passes a 0000 mode to writes; update
the logic around $mode_str and $chmod to treat '0' (and any non-octal or invalid
value) as a failure and fall back to FS_CHMOD_FILE. Specifically, in the
Installer.php code that reads $mode_str and computes $chmod, validate $mode_str
using a check like: ensure it's a non-empty octal string (e.g., matches
/^[0-7]+$/) before calling octdec and casting; otherwise set $chmod =
FS_CHMOD_FILE so put_contents() never receives 0000. Make the change where
$mode_str and $chmod are defined (referencing getchmod, $mode_str, $chmod, and
FS_CHMOD_FILE).
|
Superseded by #13 (1.0.1). After security review, we removed the wp-config.php auto-write entirely rather than ship the in-place fallback proposed here — a mid-write failure could truncate wp-config.php and fatal the whole site with no backup. #13 replaces it with a guided copy-and-paste flow plus a docs guide, switches salt generation to local-only, fixes the managed-host false-positive detection, and softens the branded-login gate to informed consent. Closing in favor of #13. |
Bug
A user hit "Could not write the new configuration. No changes were made." when running the salt-fix wizard on a real install.
Root cause:
apply_salt_fix()wrote a sibling temp file in thewp-config.phpdirectory andmove()'d it over the original. That requires the directory to be writable — but the precheck (salt_autofix_available) only verified the file (is_writable($path)) was writable. On the common hardening wherewp-config.phpis writable but its directory is locked, creating the temp failed, so the whole operation aborted even though we could have written the file.Fix
Keep the atomic temp-swap as the preferred path, but fall back to an in-place
put_contents()overwrite ofwp-config.phpwhen the temp can't be created. Overwriting an existing writable file needs no directory write access, so it works in the locked-dir setup. The replacement content was already validated by the pre-write safety gate (still valid PHP, no longer weak), so the non-atomic in-place write is sound. Original file mode is preserved on both paths (now passed directly toput_contents, no separatechmod).This means auto-write now succeeds whenever the file is writable — exactly what the preview check already promised.
Notes
1.0.1.WP_Filesystemand isn't unit-testable in the stub harness (consistent with the rest of the I/O layer); pure-logic tests unchanged and green. Verified locally: lint clean, version-consistency matches.v1.0.1release with a fresh installable zip will follow the merge.Summary by CodeRabbit